package com.ajk.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajk.server.dao.SmsMapper;
import com.ajk.server.model.Sms;
import com.ajk.server.model.query.SmsQuery;
import com.ajk.server.service.SmsService;

/**
 * 短信记录  <br>
 * t_sms <br>
 * v1.0 2016-05-01
 */
 @Service
 public class SmsServiceImpl implements SmsService {
	
	private static final Logger logger = LoggerFactory.getLogger(SmsServiceImpl.class);
	
	@Autowired
	private SmsMapper smsMapper;
	
	/**
 	*根据ID删除 短信记录
 	*/
 	@Override
 	public Integer deleteSmsById(Integer id){
 		return smsMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 短信记录
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertSms(List<? extends Sms> smss){
		Integer count = smsMapper.batchInsert(smss);
		return count;
 	}
 	/**
 	*新增 短信记录
 	*/
 	@Override
 	@Transactional
 	public Integer insertSms(Sms domain){
		Integer id = smsMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 短信记录
 	*/
 	@Override
 	@Transactional
 	public Integer updateSms(Sms domain){
		Integer count = smsMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 短信记录
 	*/
 	public Sms findSmsById(Integer id){
 		Sms result = smsMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 短信记录
 	*/
	public List<Sms> findSmsByQuery(SmsQuery query){
		query.dealWith();
		List<Sms> result = smsMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (Sms sms : result) {
				sms.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countSmsByQuery(SmsQuery query){
 		query.dealWith();
 		Integer result = smsMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<Sms> findSmsByIds(List<Integer> ids){
 		List<Sms> result = smsMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (Sms sms : result) {
				sms.dealWith();
			}
		}
		return result;
 	}
 	
}	